﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class instance : MonoBehaviour
{
    public GameObject enemy;  // 岩石预制体
    public GameObject xueGao;  // 雪糕预制体
    float xPos; // x轴 -7  7，y轴 -7  7
    float t1, t2; // 计时器
    float enemyTime; // 岩石生成的间隔时间

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        t1 += Time.deltaTime; // 岩石计时
        t2 += Time.deltaTime; // 雪糕计时
        enemyTime = Random.Range(2f, 4f);
        if (t1 > enemyTime)
        {

            xPos = Random.Range(-7, 7); // 随机位置
            Instantiate(enemy, new Vector3(xPos, 7, 0), Quaternion.identity); // 生成岩石
            // 计时器重置为 0
            t1 = 0;
        }
        if (t2 > 3)
        {
            xPos = Random.Range(-7, 7);
            Instantiate(xueGao, new Vector3(xPos, 7, 0), Quaternion.identity); // 生成雪糕
            t2 = 0;
        }
    }
}
